import {observable, action} from "mobx";
import request from "../utils/request";
import * as api from "../api/api";
import {LoadHoc, loading} from '../hoc/loadHoc';

export default class DeclareTaxStore extends LoadHoc {
  /**
   * 车辆分类数据
   */
  @observable carCategories: api.SingleUserMallCarsVOCarCategoryVO = {};

  @loading @action
  async getCarCategories(params: {
    type: number,
    callback?: (res: api.SingleUserMallCarsVOCarCategoryVO) => void;
  }) {
    const {type, callback} = params;
    const carCategories = await request(api.AppcarApiFetchParamCreactor.appcarGetCarCategoriesAsync({
      type
    }));
    this.carCategories = carCategories;
    callback && callback(carCategories);
  }

  /**
   * 车辆详情信息
   */
  @observable car: api.SingleUserMallCarsVOCarAppVO = {};

  @loading @action
  async getCar(params: {
    formCarCategoryId: number,
    formAreaCode: string,
    callback?: (res: api.SingleUserMallCarsVOCarAppVO) => void;
  }) {
    const {formCarCategoryId,formAreaCode,callback} = params;
    const car = await request(api.AppcarApiFetchParamCreactor.appcarGetCarAsync({
      formCarCategoryId,
      formAreaCode
    }));
    this.car = car;
    callback && callback(car);
  }

  /**
   * 车辆提交报税
   */
  @loading @action
  async buyCarTax(params: {
    form: {
      carNumber: string,
      isRegister: boolean,
      province: string,
      carSpecId: number,
      carUserName: string,
      carDrivePicture: string,
      carDrivePictureTwo: string,
      carUserPicture: string,
      carUserPictureTwo: string,
      buyCarPicture: string,
      carStandardPicture: string,
      createYear: number,
      payType: string,
      message: string,
      quality: number,
      carType: number,
    },
    callback?: (res) => void;
  }) {
    const {form, callback } = params;
    const car = await request(api.ApporderApiFetchParamCreactor.apporderBuyCarTaxAsync({
      form
    }));
    this.car = car;
    callback && callback(car);
  }

  /**
   * 申请税票
   */
  @loading @action
  async setCarTaxOrderAddress(params: {
    form: {
      orderId: number,
      shippingType: '0',
      receiver: string,
      receiverPhone: string,
      receiverAddress: string,
      postalCode: string,
      mailType: number,
      remarks: string,
    },
    callback?: (res) => void;
  }) {
    const {form, callback} = params;
    const car = await request(api.ApporderApiFetchParamCreactor.apporderSetCarTaxOrderAddressAsync({
      form
    }));
    this.car = car;
    callback && callback(car);
  }

  /**
   * 获取订单列表
   */
  @observable carTaxOrders: api.SingleUserMallOrdersVOOrderVO = {};

  @loading @action
  async getCarTaxOrders(params: {
    formIsShowShipping?: boolean,
    pageIndex: number,
    pageSize: number,
    callback?: (home: api.SingleUserMallOrdersVOOrderVO) => void;
  }) {
    const {formIsShowShipping, pageIndex, pageSize, callback} = params;
    const carTaxOrders = await request(api.ApporderApiFetchParamCreactor.apporderGetCarTaxOrdersAsync({
      formIsShowShipping,
      formSkipCount:  (pageIndex-1)*pageSize,
      formMaxResultCount: pageSize
    }));
    this.carTaxOrders = carTaxOrders;
    callback && callback(carTaxOrders);
  }
}
